package com.hk.admin.common.base.dto.page;

import lombok.Data;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;

import java.util.List;

/**
 * <br>
 * <b>功能：</b>返回前端分页数据<br>
 * <b>作者：</b>Pan.ShiJu<br>
 * <b>日期：</b>2017/4/11 23:27<br>
 */
@Data
public class Pagination {

    private int number;
    private int size;
    private int numberOfElements;
    private List content;
    private boolean hasContent;
    private Sort sort;
    private boolean isFirst;
    private boolean isLast;
    private boolean hasNext;
    private boolean hasPrevious;
    private int totalPages;
    private long totalElements;

    public Pagination() {
    }

    public Pagination(List content, Long totalElements) {
        this.content = content;
        this.totalElements = totalElements;
    }

    public Pagination(List content) {
        this.content = content;
    }

    public Pagination(Page page) {
        this.number = page.getNumber();
        this.size = page.getSize();
        this.numberOfElements = page.getNumberOfElements();
        this.hasContent = page.hasContent();
        this.sort = page.getSort();
        this.isFirst = page.isFirst();
        this.isLast = page.isLast();
        this.hasNext = page.hasNext();
        this.hasPrevious = page.hasPrevious();
        this.totalPages = page.getTotalPages();
        this.totalElements = page.getTotalElements();
    }


}
